
package com.lucky.back.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lucky.back.pojo.dto.MessagesAddNewDTO;
import com.lucky.back.pojo.vo.MessagesListItemVO;
import com.lucky.back.service.impl.MessagesServiceImpl;
import com.lucky.back.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jboss.logging.Messages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(tags = "08.留言板理模块")
@Validated
@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    MessagesServiceImpl messagesService;

    // http://localhost:8080/albums/add-new?name=TestAlbumName001&description=TestDescription001&sort=77
    @ApiOperation("添加留言")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated MessagesAddNewDTO messagesDTO) {
        log.debug("开始处理【添加留言】的请求，参数：{}", messagesDTO);
        messagesService.addNew(messagesDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除留言")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "留言id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id) {
        log.debug("开始处理【删除留言】的请求，参数：{}", id);
        messagesService.delete(id);
        return JsonResult.ok();
    }


    // http://localhost:9081/admins
    @ApiOperation("查询留言")
    @ApiOperationSupport(order = 200)
    @GetMapping("")
    public JsonResult<List<MessagesListItemVO>> List(){
        log.debug("开始处理请求");
        List<MessagesListItemVO> list = messagesService.list();
        return JsonResult.ok(list);
    }
}
